#include "global.h"
#include "logic_manager.h"
#include "scene_manager.h"
#include "physics_manager.h"
#include "logic_state_game.h"
#include "logic_state_main_menu.h"
#include "logic_state_scene_select.h"

logic_manager::logic_manager()
: current_state(NULL)
{
    register_state(STATE_MAIN_MENU, new logic_state_main_menu, true);
	register_state(STATE_SCENE_SELECT, new logic_state_scene_select);
	register_state(STATE_GAME_DOING, new logic_state_game);
	current_state->enter();
}

logic_manager::~logic_manager()
{

}

bool logic_manager::logic_update()
{
	get_instance()->current_state->update(hge->Timer_GetDelta());
    return false;
}

logic_state* logic_manager::get_current_state()
{
    return current_state;
}

void logic_manager::change_state_to(STATE_ID id)
{
	current_state->exit();
    current_state = logic_states[id];
	current_state->enter();
}

void logic_manager::register_state(STATE_ID id, logic_state* state, bool set_current)
{
	logic_states[id] = state;
	state->id = id;
	if (set_current)
	{
		current_state = state;
	}
}

logic_state* logic_manager::get_state_by_id(STATE_ID id)
{
    return logic_states[id];
}